home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Amiga Classic Collection
/
The Amiga Classic Collection - Disc 1.iso
/
Education
/
ED16-CrosswordCreator.DMS
/
ED16-CrosswordCreator.adf
/
Source
/
CPCDosIO.mod
< prev
next >
Wrap
Text File
|
1991-07-13
|
32KB
|
1,175 lines
IMPLEMENTATION MODULE CPCDosIO;
IMPORT Arts;
IMPORT ASCII;
IMPORT Conversions;
IMPORT FileReq;
IMPORT CPCGlobal;
IMPORT CPCRequesters;
IMPORT CPCSleep;
IMPORT DosD,DosL;
IMPORT ExecD,ExecL;
IMPORT ExecSupport;
IMPORT FileMessage;
IMPORT FileSystem;
IMPORT GraphicsD,GraphicsL;
IMPORT InOut;
IMPORT IntuiIO;
IMPORT Printer;
IMPORT RandomNumber;
IMPORT RealConversions;
IMPORT Requester;
IMPORT RequesterSet;
IMPORT String;
IMPORT SYSTEM;
CONST
errReadingMsg="ERROR READING MSGTXT.DATA:";
ioErrReadingMsg="I/O-ERROR READING MSGTXT.DATA:";
defworddir="Cross:data/";
defwordfile="words01.crw";
defdatadir="Cross:data/";
defdatafile="puzzle01.crd";
deftexdir="Cross:data/";
deftexfile="puzzle01.tex";
defmsg="Cross:data/msgtxt.data";
TYPE
IOMode=(readW,readC,writeC,printC,printS);
CharPtr=POINTER TO CHAR;
VAR
printer,parallel: DosD.FileHandlePtr;
myfile: FileSystem.File;
filepresent: BOOLEAN;
initialized: BOOLEAN;
dataReq,wordReq,texReq: FileReq.FileRequestData;
scr: IntuiIO.SCREEN;
PROCEDURE InitCPCDosIO;
BEGIN
IF NOT initialized THEN
FileReq.MakeFRD("",defwordfile,defworddir,
SYSTEM.CAST(SYSTEM.ADDRESS,CPCGlobal.window),10,10,wordReq);
FileReq.MakeFRD("",defdatafile,defdatadir,
SYSTEM.CAST(SYSTEM.ADDRESS,CPCGlobal.window),10,10,dataReq);
FileReq.MakeFRD("",deftexfile,deftexdir,
SYSTEM.CAST(SYSTEM.ADDRESS,CPCGlobal.window),10,10,texReq);
CPCGlobal.words[0]:=NIL;
CPCGlobal.words[1]:=NIL;
END;
initialized:=TRUE;
END InitCPCDosIO;
PROCEDURE Value(a: ARRAY OF CHAR): INTEGER;
VAR err,sgn: BOOLEAN;
val: LONGINT;
l: INTEGER;
BEGIN
FOR l:=0 TO String.Length(a) DO
IF (a[l]=" ") THEN
a[l]:="0";
END;
END;
sgn:=FALSE;
Conversions.StrToVal(a,val,sgn,10,err);
IF err THEN
RETURN -1;
ELSE
RETURN INTEGER(val);
END;
END Value;
PROCEDURE MakeComStr(VAR s: ARRAY OF CHAR; c0,c1,c2,c3,c4,c5,c6,c7: CHAR);
BEGIN
s[0]:=c0;
s[1]:=c1;
s[2]:=c2;
s[3]:=c3;
s[4]:=c4;
s[5]:=c5;
s[6]:=c6;
s[7]:=c7;
s[8]:="\o";
END MakeComStr;
PROCEDURE Put(fileh: DosD.FileHandlePtr; s: FileMessage.StrPtr;
l: LONGINT): BOOLEAN; (* TRUE if error *)
BEGIN
IF l=0 THEN
l:=String.Length(s^);
END;
RETURN DosL.Write(fileh,s,l)#l;
END Put;
PROCEDURE readline(VAR f: FileSystem.File; VAR a,number: CPCGlobal.LString; m: MsgMode);
VAR c: CHAR;
n: INTEGER;
sp: FileMessage.StrPtr;
BEGIN
n:=0;
FileSystem.ReadChar(f,c);
IF (c>="0") AND (c<="9") THEN
a[n]:=c;
INC(n);
REPEAT
CPCGlobal.myAssert(n<=CPCGlobal.lStringLen,SYSTEM.ADR(errReadingMsg),SYSTEM.ADR("STRING TOO LONG"));
FileSystem.ReadChar(f,c);
FileMessage.ResponseText(f.res,sp);
CPCGlobal.myAssert(f.res=FileSystem.done,SYSTEM.ADR(ioErrReadingMsg),sp);
a[n]:=c;
INC(n);
UNTIL (c=" ");
a[n-1]:="\o";
number:=a;
IF (m=nonumbers) THEN
n:=0;
a[0]:="\o";
ELSE
DEC(n);
END;
ELSE
number:="illegal";
a[0]:=c;
n:=1;
END;
REPEAT
CPCGlobal.myAssert(n<=CPCGlobal.lStringLen,SYSTEM.ADR(errReadingMsg),SYSTEM.ADR("STRING TOO LONG"));
FileSystem.ReadChar(f,c);
FileMessage.ResponseText(f.res,sp);
CPCGlobal.myAssert(f.res=FileSystem.done,SYSTEM.ADR(ioErrReadingMsg),sp);
IF (c="@") THEN
c:=" ";
END;
a[n]:=c;
INC(n);
UNTIL (c=ASCII.lf);
a[n-1]:="\o";
END readline;
PROCEDURE ReadMsg(m: MsgMode);
VAR c: CHAR;
lcount,i,k,l,n,langno: INTEGER;
a,num: CPCGlobal.LString;
b: ARRAY[1..9] OF CPCGlobal.LString;
sp: FileMessage.StrPtr;
BEGIN
FileSystem.Lookup(myfile,defmsg,5000,FALSE);
filepresent:=TRUE;
CPCGlobal.myAssert(myfile.res=FileSystem.done,SYSTEM.ADR(ioErrReadingMsg),SYSTEM.ADR("CAN'T OPEN MSGTXT.DATA"));
FileSystem.ReadChar(myfile,c);
CPCGlobal.myAssert((c>"0")&(c<":"),SYSTEM.ADR(errReadingMsg),SYSTEM.ADR("ILLEGAL LANGUAGE COUNT"));
lcount:=(ORD(c)-ORD("0"));
FileSystem.ReadChar(myfile,c);
FileMessage.ResponseText(myfile.res,sp);
CPCGlobal.myAssert(myfile.res=FileSystem.done,SYSTEM.ADR(ioErrReadingMsg),sp);
CPCGlobal.myAssert(c=ASCII.lf,SYSTEM.ADR(errReadingMsg),SYSTEM.ADR("LC IS LONGER THAN ONE CHAR"));
InOut.WriteLn; InOut.WriteLn;
InOut.WriteString("Crossword Puzzle Creator: Language selection.");
InOut.WriteLn; InOut.WriteLn;
FOR l:=1 TO lcount DO
n:=0;
REPEAT
CPCGlobal.myAssert(n<=CPCGlobal.lStringLen,SYSTEM.ADR("ERROR IN MSG.TXT:"),SYSTEM.ADR("STRING TOO LONG"));
FileSystem.ReadChar(myfile,c);
FileMessage.ResponseText(myfile.res,sp);
CPCGlobal.myAssert(myfile.res=FileSystem.done,SYSTEM.ADR(ioErrReadingMsg),sp);
a[n]:=c;
INC(n);
UNTIL (c=ASCII.lf);
a[n-1]:="\o";
String.Copy(b[l],a);
InOut.WriteInt(l,1); InOut.WriteString(": ");
InOut.WriteString(b[l]);
InOut.WriteLn;
END;
InOut.WriteLn;
REPEAT
InOut.WriteString("Please select (press return when finished): ");
InOut.Read(c);
langno:=ORD(c)-ORD("0");
UNTIL ((langno>=1) AND (langno<=lcount));
InOut.WriteLn; InOut.WriteLn;
InOut.WriteString("Reading program messages... please wait!");
InOut.WriteLn;
InOut.WriteString("LANGUAGE="); InOut.WriteString(b[langno]);
InOut.WriteLn;
k:=1;
REPEAT
FOR l:=1 TO lcount DO
readline(myfile,a,num,m);
IF (l=langno) THEN
String.Copy(CPCGlobal.msg[k],a);
IF ((k#Value(num)) AND (Value(num)#999)) THEN
IF (Value(num)>=0) THEN
InOut.WriteString("illegal message number encountered in msgtxt.data...\n");
InOut.WriteString("message number should be..... "); InOut.WriteInt(k,0);
InOut.WriteString("\nmessage number is actually... "); InOut.WriteInt(Value(num),0);
InOut.WriteString("\nstring read: '"); InOut.WriteString(a); InOut.WriteString("'\n");
CPCGlobal.myAssert(FALSE,SYSTEM.ADR(errReadingMsg),
SYSTEM.ADR("ILLEGAL MESSAGE NUMBER"));
ELSE
InOut.WriteString("message number missing in msgtxt.data...\n");
InOut.WriteString("message number should be "); InOut.WriteInt(k,0);
InOut.WriteString("\nstring read: '"); InOut.WriteString(a); InOut.WriteString("'\n");
CPCGlobal.myAssert(FALSE,SYSTEM.ADR(errReadingMsg),
SYSTEM.ADR("MESSAGE NUMBER MISSING"));
END;
END;
END;
END;
INC(k);
CPCGlobal.myAssert((k<=CPCGlobal.maxmsg) OR (Value(num)=999),
SYSTEM.ADR(errReadingMsg),
SYSTEM.ADR("TOO MANY MESSAGES"));
UNTIL (Value(num)=999);
InOut.WriteLn; InOut.WriteLn;
IF filepresent THEN
filepresent:=FALSE;
FileSystem.Close(myfile);
END;
END ReadMsg;
PROCEDURE HandleIOErr(action: IOMode; body: ARRAY OF CHAR): BOOLEAN;
VAR
header: CPCGlobal.LString;
t: ARRAY[0..1] OF Requester.Text;
res: BOOLEAN;
BEGIN
CASE action OF
|readW: String.Copy(t[0],CPCGlobal.msg[5]);
|readC: String.Copy(t[0],CPCGlobal.msg[6]);
|writeC: String.Copy(t[0],CPCGlobal.msg[7]);
|printC: String.Copy(t[0],CPCGlobal.msg[8]);
|printS: String.Copy(t[0],CPCGlobal.msg[9]);
|ELSE CPCGlobal.myAssert(FALSE,SYSTEM.ADR(CPCGlobal.msg[10]),SYSTEM.ADR(CPCGlobal.msg[11]));
END;
String.Copy(t[1],body);
Requester.SetReqBorderPen(1);
Requester.SetReqTextPen(0);
CPCSleep.NormalPointer;
res:=RequesterSet.BooleanRequest(CPCGlobal.window,50,50,540,50,t,
SYSTEM.ADR(CPCGlobal.msg[12]),
SYSTEM.ADR(CPCGlobal.msg[13]),"\o","\o",
Requester.ReqFlagSet{Requester.reqBorder,Requester.reqShadow});
CPCSleep.SleepPointer;
RETURN res;
END HandleIOErr;
PROCEDURE GetWordFileName(VAR name: FileReq.FileString; force: BOOLEAN): BOOLEAN;
VAR
quit: BOOLEAN;
BEGIN
String.Copy(wordReq.h,CPCGlobal.msg[69]);
REPEAT
CPCSleep.NormalPointer;
FileReq.FileReq(wordReq,name);
CPCSleep.SleepPointer;
quit:=FALSE;
IF (force) AND (String.Length(name)=0) THEN
CPCSleep.NormalPointer;
quit:=CPCRequesters.YesOrNo(CPCGlobal.msg[79]);
CPCSleep.SleepPointer;
END;
UNTIL (NOT force) OR (String.Length(name)>0) OR quit;
RETURN quit;
END GetWordFileName;
PROCEDURE DoWord(VAR inx: CharPtr; VAR num: INTEGER): BOOLEAN;
BEGIN
INC(num);
CPCGlobal.words[num]:=SYSTEM.CAST(CPCGlobal.StringPtr,inx);
WHILE (inx^#"\n") AND (inx^#"\o") DO
inx^:=String.ANSICap(inx^);
INC(inx);
END;
IF inx^="\o" THEN
INC(inx);
RETURN TRUE
ELSE
inx^:="\o";
INC(inx);
RETURN FALSE;
END;
END DoWord;
PROCEDURE ReadWords(forcewords: BOOLEAN): INTEGER;
VAR again: BOOLEAN;
num: INTEGER;
filesize,dummy: LONGINT;
body: CPCGlobal.LString;
inx: CharPtr;
name: FileReq.FileString;
wordfh: DosD.FileHandlePtr;
BEGIN
body:="";
LOOP
num:=0;
IF GetWordFileName(name,forcewords) THEN Arts.Terminate END;
IF String.Length(name)=0 THEN EXIT END;
LOOP
wordfh:=DosL.Open(SYSTEM.ADR(name),DosD.readOnly);
IF wordfh=NIL THEN
String.Copy(body,CPCGlobal.msg[16]);
EXIT;
END;
dummy:=DosL.Seek(wordfh,0,DosD.end);
filesize:=DosL.Seek(wordfh,0,DosD.beginning);
IF (CPCGlobal.words[0]#NIL) AND (CPCGlobal.words[1]#NIL) THEN
ExecL.FreeMem(CPCGlobal.words[1],SYSTEM.CAST(LONGINT,CPCGlobal.words[0]));
END;
CPCGlobal.words[0]:=SYSTEM.CAST(SYSTEM.ADDRESS,filesize+1);
CPCGlobal.words[1]:=ExecL.AllocMem(filesize+1,ExecD.MemReqSet{ExecD.public});
dummy:=DosL.Read(wordfh,CPCGlobal.words[1],filesize);
DosL.Close(wordfh);
wordfh:=NIL;
IF dummy#filesize THEN
String.Copy(body,CPCGlobal.msg[22]);
EXIT;
END;
inx:=SYSTEM.CAST(CharPtr,SYSTEM.CAST(LONGINT,CPCGlobal.words[1])+filesize);
(* now inx points to the last byte of the word buffer, one beyond the *)
(* last byte of our file... *)
inx^:="\o";
(* make sure the buffer ends with a "\o"; saves us a range check in DoWord *)
inx:=SYSTEM.CAST(CharPtr,CPCGlobal.words[1]);
num:=0;
REPEAT UNTIL (DoWord(inx,num)) OR (num=CPCGlobal.maxwords);
IF num=CPCGlobal.maxwords THEN
String.Copy(body,CPCGlobal.msg[21]);
EXIT;
END;
EXIT;
END;
IF String.Length(body)#0 THEN
again:=forcewords OR HandleIOErr(readW,body);
ELSE
again:=FALSE;
END;
IF (NOT again) THEN
EXIT;
END;
END;
IF String.Compare(CPCGlobal.words[num]^,"***END***")=0 THEN
DEC(num);
END;
RETURN num;
END ReadWords;
PROCEDURE SaveData();
VAR a: FileReq.FileString;
s: CPCGlobal.String;
act: LONGINT;
x,y,l: INTEGER;
err,again: BOOLEAN;
body: CPCGlobal.LString;
BEGIN
LOOP
String.Copy(dataReq.h,CPCGlobal.msg[70]);
CPCSleep.NormalPointer;
FileReq.FileReq(dataReq,a);
CPCSleep.SleepPointer;
IF String.Length(a)=0 THEN EXIT END;
LOOP
String.Copy(body,CPCGlobal.msg[16]);
FileSystem.Lookup(myfile,a,5000,TRUE);
filepresent:=TRUE;
IF (myfile.res#FileSystem.done) THEN EXIT END;
String.Copy(body,CPCGlobal.msg[25]);
FileSystem.WriteBytes(myfile,SYSTEM.ADR("cpcdata!"),8,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
Conversions.ValToStr(CPCGlobal.hori,FALSE,s,10,4," ",err);
FileSystem.WriteBytes(myfile,SYSTEM.ADR(s),4,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
Conversions.ValToStr(CPCGlobal.vert,FALSE,s,10,4," ",err);
FileSystem.WriteBytes(myfile,SYSTEM.ADR(s),4,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
Conversions.ValToStr(CPCGlobal.xmax,FALSE,s,10,4," ",err);
FileSystem.WriteBytes(myfile,SYSTEM.ADR(s),4,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
Conversions.ValToStr(CPCGlobal.ymax,FALSE,s,10,4," ",err);
FileSystem.WriteBytes(myfile,SYSTEM.ADR(s),4,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
FOR y:=1 TO CPCGlobal.ymax DO
FOR x:=1 TO CPCGlobal.xmax DO
FileSystem.WriteChar(myfile,CPCGlobal.text[x,y]);
IF (myfile.res#FileSystem.done) THEN EXIT END;
END;
END;
FOR l:=0 TO CPCGlobal.hori+CPCGlobal.vert-1 DO
FileSystem.WriteBytes(myfile,SYSTEM.ADR(CPCGlobal.kwr[l]),String.Length(CPCGlobal.kwr[l]),act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
FileSystem.WriteChar(myfile,ASCII.lf);
IF (myfile.res#FileSystem.done) THEN EXIT END;
END;
EXIT;
END;
IF (myfile.res#FileSystem.done) THEN
again:=HandleIOErr(writeC,body);
ELSE
again:=FALSE;
END;
IF (NOT again) THEN EXIT END;
IF filepresent THEN
filepresent:=FALSE;
FileSystem.Close(myfile);
END;
END;
IF filepresent THEN
filepresent:=FALSE;
FileSystem.Close(myfile);
END;
END SaveData;
PROCEDURE LoadData();
VAR a: FileReq.FileString;
s: CPCGlobal.String;
act: LONGINT;
x,y,l,cnt: INTEGER;
err,again: BOOLEAN;
val: LONGINT;
body: CPCGlobal.LString;
BEGIN
LOOP
String.Copy(dataReq.h,CPCGlobal.msg[71]);
CPCSleep.NormalPointer;
FileReq.FileReq(dataReq,a);
CPCSleep.SleepPointer;
IF String.Length(a)=0 THEN EXIT END;
LOOP
String.Copy(body,CPCGlobal.msg[16]);
FileSystem.Lookup(myfile,a,5000,FALSE);
filepresent:=TRUE;
IF (myfile.res#FileSystem.done) THEN EXIT END;
String.Copy(body,CPCGlobal.msg[34]);
FileSystem.ReadBytes(myfile,SYSTEM.ADR(s),8,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
IF String.Compare(s,"cpcdata!")#0 THEN
String.Copy(body,CPCGlobal.msg[35]);
myfile.res:=FileSystem.notdone;
EXIT;
ELSE
s[4]:="\o";
FileSystem.ReadBytes(myfile,SYSTEM.ADR(s),4,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
CPCGlobal.hori:=Value(s);
FileSystem.ReadBytes(myfile,SYSTEM.ADR(s),4,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
CPCGlobal.vert:=Value(s);
FileSystem.ReadBytes(myfile,SYSTEM.ADR(s),4,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
CPCGlobal.xmax:=Value(s);
FileSystem.ReadBytes(myfile,SYSTEM.ADR(s),4,act);
IF (myfile.res#FileSystem.done) THEN EXIT END;
CPCGlobal.ymax:=Value(s);
FOR x:=0 TO CPCGlobal.maxgrid DO
FOR y:=0 TO CPCGlobal.maxgrid DO
CPCGlobal.text[x,y]:="\o";
END;
END;
FOR y:=1 TO CPCGlobal.ymax DO
FOR x:=1 TO CPCGlobal.xmax DO
FileSystem.ReadChar(myfile,CPCGlobal.text[x,y]);
IF (myfile.res#FileSystem.done) THEN EXIT END;
END;
END;
FOR l:=0 TO CPCGlobal.hori+CPCGlobal.vert-1 DO
cnt:=-1;
REPEAT
INC(cnt);
FileSystem.ReadChar(myfile,s[cnt]);
IF (myfile.res#FileSystem.done) THEN EXIT END;
UNTIL (s[cnt]=ASCII.lf);
s[cnt]:="\o";
String.Copy(CPCGlobal.kwr[l],s);
END;
END;
EXIT;
END;
IF (myfile.res#FileSystem.done) THEN
again:=HandleIOErr(readC,body);
ELSE
again:=FALSE;
END;
IF (NOT again) THEN EXIT END;
IF filepresent THEN
filepresent:=FALSE;
FileSystem.Close(myfile);
END;
END;
IF filepresent THEN
filepresent:=FALSE;
FileSystem.Close(myfile);
END;
END LoadData;
PROCEDURE PrintSolution;
VAR s: CPCGlobal.String;
a,b: INTEGER;
body: CPCGlobal.LString;
err,again: BOOLEAN;
BEGIN
LOOP
LOOP
err:=TRUE;
String.Copy(body,CPCGlobal.msg[36]);
printer:=DosL.Open(SYSTEM.ADR("PRT:"),DosD.newFile);
IF (printer=NIL) THEN
String.Copy(body,CPCGlobal.msg[37]);
EXIT;
END;
MakeComStr(s,ASCII.esc,"c","\o","\o","\o","\o","\o","\o");
IF Put(printer,SYSTEM.ADR(s),3) THEN EXIT END;
MakeComStr(s,ASCII.esc,"[","0","z","\o","\o","\o","\o");
IF Put(printer,SYSTEM.ADR(s),5) THEN EXIT END;
FOR a:=1 TO CPCGlobal.ymax DO
FOR b:=1 TO CPCGlobal.xmax DO
IF (CPCGlobal.text[b,a]="\o") THEN
s[0]:=" ";
IF Put(printer,SYSTEM.ADR(s),1) THEN EXIT END;
ELSE
IF Put(printer,SYSTEM.ADR(CPCGlobal.text[b,a]),1) THEN EXIT END;
END;
END;
s[0]:=ASCII.lf;
IF Put(printer,SYSTEM.ADR(s),1) THEN EXIT END;
END;
MakeComStr(s,ASCII.esc,"c","\o","\o","\o","\o","\o","\o");
IF Put(printer,SYSTEM.ADR(s),0) THEN EXIT END;
err:=FALSE;
EXIT;
END;
IF (err) THEN
again:=HandleIOErr(printS,body);
ELSE
again:=FALSE;
END;
IF (NOT again) THEN EXIT END;
DosL.Close(printer);
printer:=NIL;
END;
DosL.Close(printer);
printer:=NIL;
END PrintSolution;
PROCEDURE PutWordList(medium: DosD.FileHandlePtr; tex: BOOLEAN): BOOLEAN;
VAR
sorted,converr: BOOLEAN;
n,l1,l2,lastlen,pos: INTEGER;
temp: CPCGlobal.String;
out: ARRAY[0..100] OF CHAR;
BEGIN
REPEAT
sorted:=TRUE;
FOR n:=1 TO CPCGlobal.hori+CPCGlobal.vert-1 DO
l1:=String.Length(CPCGlobal.kwr[n-1]);
l2:=String.Length(CPCGlobal.kwr[n]);
IF (l1<l2) OR ((l1=l2) AND (String.Compare(CPCGlobal.kwr[n-1],CPCGlobal.kwr[n])<0)) THEN
String.Copy(temp,CPCGlobal.kwr[n-1]);
String.Copy(CPCGlobal.kwr[n-1],CPCGlobal.kwr[n]);
String.Copy(CPCGlobal.kwr[n],temp);
sorted:=FALSE;
END;
END;
UNTIL sorted;
out:="\n\n\n";
IF Put(medium,SYSTEM.ADR(out),3) THEN RETURN TRUE END;
IF tex THEN
IF Put(medium,SYSTEM.ADR(" \\begin{list}{}{\\listparindent0pt}\n"),0) THEN
RETURN TRUE;
END;
END;
n:=-1;
lastlen:=10000;
REPEAT
INC(n);
IF String.Length(CPCGlobal.kwr[n])#lastlen THEN
lastlen:=String.Length(CPCGlobal.kwr[n]);
Conversions.ValToStr(String.Length(CPCGlobal.kwr[n]),FALSE,out,10,2," ",converr);
out[2]:=":";
out[3]:="\o";
IF tex THEN
IF Put(medium,SYSTEM.ADR(" \\item[\\bf "),0) THEN RETURN TRUE END;
IF Put(medium,SYSTEM.ADR(out),0) THEN RETURN TRUE END;
IF Put(medium,SYSTEM.ADR("]\n"),0) THEN RETURN TRUE END;
out:=" ";
ELSE
out[3]:=" ";
out[4]:="\o";
END;
ELSE
out:=" ";
END;
String.Concat(out,CPCGlobal.kwr[n]);
String.ConcatChar(out," ");
REPEAT
INC(n);
IF String.Length(CPCGlobal.kwr[n])=lastlen THEN
String.Insert(out,String.last,CPCGlobal.kwr[n]);
String.ConcatChar(out," ");
END;
UNTIL (n>=CPCGlobal.hori+CPCGlobal.vert-1) OR (String.Length(out)+String.Length(CPCGlobal.kwr[n+1])+2>=78)
OR (String.Length(CPCGlobal.kwr[n])#lastlen);
IF (n>=CPCGlobal.hori+CPCGlobal.vert-1) THEN
REPEAT
pos:=String.Length(out);
IF (out[pos-1]=" ") THEN
out[pos-1]:="\o";
END;
UNTIL (out[pos-1]#"\o");
END;
IF String.Length(CPCGlobal.kwr[n])#lastlen THEN
DEC(n);
END;
IF Put(medium,SYSTEM.ADR(out),0) THEN RETURN TRUE END;
out[0]:="\n";
IF Put(medium,SYSTEM.ADR(out),1) THEN RETURN TRUE END;
UNTIL (n>=CPCGlobal.hori+CPCGlobal.vert-1);
IF tex THEN
IF Put(medium,SYSTEM.ADR("\\end{list}\n"),0) THEN RETURN TRUE END;
END;
RETURN FALSE;
END PutWordList;
PROCEDURE PrintEpsonCross;
VAR
full: ARRAY [0..10] OF CPCGlobal.String;
mt: ARRAY [1..2] OF CPCGlobal.String;
graphon,graphoff,temp: CPCGlobal.String;
out: ARRAY [0..100] OF CHAR;
POW2: ARRAY[0..7] OF INTEGER;
m,n,ou,x,y,width: INTEGER;
s: CHAR;
act: LONGINT;
sorted,err,again: BOOLEAN;
pos,dotno: INTEGER;
body: CPCGlobal.LString;
l1,l2: INTEGER;
lastlen: INTEGER;
converr: BOOLEAN;
BEGIN
LOOP
LOOP
err:=TRUE;
String.Copy(body,CPCGlobal.msg[38]);
parallel:=DosL.Open(SYSTEM.ADR("PAR:"),DosD.newFile);
IF (parallel=NIL) THEN
String.Copy(body,CPCGlobal.msg[39]);
EXIT;
END;
width:=640 DIV CPCGlobal.xmax;
IF (width>16) THEN
width:=16;
END;
POW2[0]:=1; POW2[1]:=2; POW2[2]:=4; POW2[3]:=8;
POW2[4]:=16; POW2[5]:=32; POW2[6]:=64; POW2[7]:=128;
FOR m:=0 TO 10 DO
FOR n:=0 TO width-1 DO
dotno:=RandomNumber.RND(8);
temp[n]:=CHAR(POW2[dotno]);
END;
temp[width]:="\o";
String.Copy(full[m],temp);
END;
mt[1,0]:=CHAR(255);
mt[2,0]:=CHAR(255);
FOR n:=1 TO width-2 DO
mt[1,n]:=CHAR(128);
mt[2,n]:=CHAR(1);
END;
mt[1,width-1]:=CHAR(255);
mt[2,width-1]:=CHAR(255);
MakeComStr(graphon,ASCII.esc,"A",CHAR(8),ASCII.esc,"*",CHAR(4),
CHAR((CPCGlobal.xmax*width) MOD 256),CHAR((CPCGlobal.xmax*width) DIV 256));
MakeComStr(graphoff,ASCII.esc,"A",ASCII.lf,"\o","\o","\o","\o","\o");
FOR y:=1 TO CPCGlobal.ymax DO
FOR ou:=1 TO 2 DO
IF Put(parallel,SYSTEM.ADR(graphon),0) THEN EXIT END;
FOR x:=1 TO CPCGlobal.xmax DO
IF (CPCGlobal.text[x,y]="\o") THEN
n:=RandomNumber.RND(11);
IF Put(parallel,SYSTEM.ADR(full[n]),width) THEN EXIT END;
ELSE
IF Put(parallel,SYSTEM.ADR(mt[ou]),width) THEN EXIT END;
END;
END;
s:=ASCII.lf;
IF Put(parallel,SYSTEM.ADR(s),1) THEN EXIT END;
END;
END;
IF Put(parallel,SYSTEM.ADR(graphoff),0) THEN EXIT END;
DosL.Close(parallel);
parallel:=NIL;
printer:=DosL.Open(SYSTEM.ADR("PRT:"),DosD.newFile);
IF printer=NIL THEN
String.Copy(body,CPCGlobal.msg[37]);
EXIT;
END;
IF PutWordList(printer,FALSE) THEN EXIT END;
err:=FALSE;
EXIT;
END;
IF (err) THEN
again:=HandleIOErr(printC,body);
ELSE
again:=FALSE;
END;
IF (NOT again) THEN EXIT END;
IF parallel#NIL THEN
DosL.Close(parallel);
parallel:=NIL;
END;
IF printer#NIL THEN
DosL.Close(printer);
printer:=NIL;
END;
END;
IF parallel#NIL THEN
DosL.Close(parallel);
parallel:=NIL;
END;
IF printer#NIL THEN
DosL.Close(printer);
printer:=NIL;
END;
END PrintEpsonCross;
PROCEDURE DoField(x,y,xfac,yfac: INTEGER; frame: BOOLEAN;
rport: GraphicsD.RastPortPtr);
VAR
i: INTEGER;
bdum: BOOLEAN;
BEGIN
IF frame THEN
GraphicsL.SetAPen(rport,1);
GraphicsL.Move(rport,x*xfac,y*yfac);
GraphicsL.Draw(rport,x*xfac+xfac,y*yfac);
GraphicsL.Draw(rport,x*xfac+xfac,y*yfac+yfac);
GraphicsL.Draw(rport,x*xfac,y*yfac+yfac);
GraphicsL.Draw(rport,x*xfac,y*yfac);
ELSE
GraphicsL.SetAPen(rport,1);
FOR i:=0 TO (xfac*yfac) DIV 7 DO
bdum:=GraphicsL.WritePixel(rport,x*xfac+RandomNumber.RND(xfac),
y*yfac+RandomNumber.RND(yfac));
END;
END;
END DoField;
PROCEDURE PrintFancyCross;
VAR
x,y: INTEGER;
scr: IntuiIO.SCREEN;
xfac,yfac: INTEGER;
rport: GraphicsD.RastPortPtr;
vport: GraphicsD.ViewPortPtr;
n: ARRAY[0..20] OF CHAR;
prtport: ExecD.MsgPortPtr;
again: BOOLEAN;
drpreq: Printer.IODRPReq;
BEGIN
xfac:=900 DIV CPCGlobal.xmax;
IF xfac>30 THEN
xfac:=30;
END;
yfac:=900 DIV CPCGlobal.ymax;
IF yfac>30 THEN
yfac:=30;
END;
IF xfac>yfac THEN
xfac:=yfac;
ELSE
yfac:=xfac;
END;
n:="";
scr:=IntuiIO.OpenScreen(n,0,1000,CPCGlobal.xmax*xfac+5,CPCGlobal.ymax*yfac+5,1,
IntuiIO.ScreenTypeSet{IntuiIO.hires,IntuiIO.interlace});
rport:=IntuiIO.ScreenRastPort(scr);
vport:=IntuiIO.GetViewPort(scr);
GraphicsL.ClearScreen(rport);
FOR x:=1 TO CPCGlobal.xmax DO
FOR y:=1 TO CPCGlobal.ymax DO
DoField(x-1,y-1,xfac,yfac,CPCGlobal.text[x,y]#"\o",rport);
END;
END;
GraphicsL.SetRGB4(vport,0,15,15,15);
GraphicsL.SetRGB4(vport,1,0,0,0);
REPEAT
prtport:=ExecSupport.CreatePort(SYSTEM.ADR("cross.printer.port"),0);
IF prtport=NIL THEN
again:=HandleIOErr(printC,CPCGlobal.msg[19]);
ELSE
again:=FALSE;
END;
UNTIL NOT again;
IF prtport#NIL THEN
REPEAT
ExecL.OpenDevice(SYSTEM.ADR("printer.device"),0,
SYSTEM.ADR(drpreq),SYSTEM.LONGSET{});
IF drpreq.device=NIL THEN
again:=HandleIOErr(printC,CPCGlobal.msg[20]);
ELSE
again:=FALSE;
END;
UNTIL NOT again;
IF drpreq.device#NIL THEN
drpreq.message.replyPort:=prtport;
drpreq.command:=Printer.dumpRPort;
drpreq.rastPort:=rport;
drpreq.colorMap:=vport^.colorMap;
drpreq.modes:=vport^.modes;
drpreq.srcX:=0;
drpreq.srcY:=0;
drpreq.srcWidth:=CPCGlobal.xmax*xfac+5;
drpreq.srcHeight:=CPCGlobal.ymax*yfac+5;
drpreq.destCols:=(CPCGlobal.xmax*xfac+5)*4;
drpreq.destRows:=0;
drpreq.special:=Printer.SpecialSet{Printer.noFormFeed,
Printer.aspect,Printer.center};
ExecL.DoIO(SYSTEM.ADR(drpreq));
END;
END;
IF drpreq.device#NIL THEN
ExecL.CloseDevice(SYSTEM.ADR(drpreq));
drpreq.device:=NIL;
END;
IF prtport#NIL THEN
ExecSupport.DeletePort(prtport);
prtport:=NIL;
END;
IntuiIO.CloseScreen(scr);
scr:=SYSTEM.CAST(IntuiIO.SCREEN,NIL);
REPEAT
printer:=DosL.Open(SYSTEM.ADR("PRT:"),DosD.newFile);
IF printer=NIL THEN
again:=HandleIOErr(printC,CPCGlobal.msg[37]);
ELSE
again:=FALSE;
END;
UNTIL NOT again;
n:="\n\e#1\e[1z\n\o";
again:=Put(printer,SYSTEM.ADR(n),0);
REPEAT
IF PutWordList(printer,FALSE) THEN
again:=HandleIOErr(printC,CPCGlobal.msg[36]);
ELSE
again:=FALSE;
END;
UNTIL NOT again;
IF printer#NIL THEN
DosL.Close(printer);
printer:=NIL;
END;
END PrintFancyCross;
PROCEDURE PrintPlainCross;
VAR
linea,lineb: ARRAY[0..CPCGlobal.maxgrid*2+5] OF CHAR;
i,x,y: INTEGER;
err,again: BOOLEAN;
body: CPCGlobal.LString;
BEGIN
LOOP
LOOP
err:=TRUE;
String.Copy(body,CPCGlobal.msg[36]);
printer:=DosL.Open(SYSTEM.ADR("PRT:"),DosD.newFile);
IF printer=NIL THEN
String.Copy(body,CPCGlobal.msg[37]);
EXIT;
END;
MakeComStr(linea,"\e","[","0","z","\o","\o","\o","\o");
IF Put(printer,SYSTEM.ADR(linea),0) THEN EXIT END;
linea:="+";
FOR i:=1 TO CPCGlobal.xmax DO
String.Concat(linea,"-+");
END;
String.ConcatChar(linea,"\n");
IF Put(printer,SYSTEM.ADR(linea),0) THEN EXIT END;
FOR y:=1 TO CPCGlobal.ymax DO
lineb:="|";
FOR x:=1 TO CPCGlobal.xmax DO
IF CPCGlobal.text[x,y]="\o" THEN
String.Concat(lineb,"#|");
ELSE
String.Concat(lineb," |");
END;
END;
String.ConcatChar(lineb,"\n");
IF Put(printer,SYSTEM.ADR(lineb),0) THEN EXIT END;
IF Put(printer,SYSTEM.ADR(linea),0) THEN EXIT END;
END;
MakeComStr(linea,"\e","[","1","z","\n","\o","\o","\o");
IF Put(printer,SYSTEM.ADR(linea),0) THEN EXIT END;
IF PutWordList(printer,FALSE) THEN EXIT END;
err:=FALSE;
EXIT;
END;
IF err THEN
again:=HandleIOErr(printC,body);
ELSE
again:=FALSE;
END;
IF NOT again THEN EXIT END;
END;
IF printer#NIL THEN
DosL.Close(printer);
printer:=NIL;
END;
END PrintPlainCross;
PROCEDURE Real2Str(r: REAL; VAR s: ARRAY OF CHAR);
VAR
dum: BOOLEAN;
BEGIN
RealConversions.RealToStr(r,s,8,2,FALSE,dum);
WHILE s[0]=" " DO
String.DeleteChar(s,String.first);
END;
END Real2Str;
PROCEDURE Int2Str(i: INTEGER; VAR s: ARRAY OF CHAR);
VAR
dum: BOOLEAN;
BEGIN
Conversions.ValToStr(i,FALSE,s,10,0," ",dum);
END Int2Str;
PROCEDURE PrintTexCross;
VAR
x,y: INTEGER;
err,again,dum: BOOLEAN;
out: DosD.FileHandlePtr;
fac: REAL;
nums: ARRAY[0..20] OF CHAR;
name: FileReq.FileString;
body: CPCGlobal.LString;
BEGIN
name:="";
REPEAT
String.Copy(texReq.h,CPCGlobal.msg[90]);
CPCSleep.NormalPointer;
FileReq.FileReq(texReq,name);
CPCSleep.SleepPointer;
IF String.Length(name)=0 THEN
err:=FALSE;
ELSE
out:=DosL.Open(SYSTEM.ADR(name),DosD.newFile);
IF out=NIL THEN
err:=TRUE;
String.Copy(body,CPCGlobal.msg[91]);
ELSE
String.Copy(body,CPCGlobal.msg[92]);
fac:=18.0/REAL(CPCGlobal.xmax);
IF 18.0/REAL(CPCGlobal.ymax)<fac THEN
fac:=18.0/REAL(CPCGlobal.ymax);
END;
err:=err OR Put(out,SYSTEM.ADR("\\documentstyle{article}\n"),0);
err:=err OR Put(out,
SYSTEM.ADR("\\hoffset-2cm \\oddsidemargin0pt \\textwidth18.5cm\n"),0);
err:=err OR Put(out,SYSTEM.ADR("\\begin{document}\n"),0);
err:=err OR Put(out,SYSTEM.ADR(" \\unitlength"),0);
Real2Str(fac,nums);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
err:=err OR Put(out,SYSTEM.ADR("cm\n"),0);
err:=err OR Put(out,SYSTEM.ADR(" \\begin{picture}("),0);
Int2Str(CPCGlobal.xmax,nums);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
err:=err OR Put(out,SYSTEM.ADR(",\o"),0);
Int2Str(CPCGlobal.ymax,nums);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
err:=err OR Put(out,SYSTEM.ADR(")\n"),0);
FOR x:=1 TO CPCGlobal.xmax DO
FOR y:=1 TO CPCGlobal.ymax DO
IF CPCGlobal.text[x,y]#"\o" THEN
(*=====================================================================*)
(*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
(* WARNING TO ALL YOU LaTeX-USERS OUT THERE: *)
(* DO NOT REPLACE THE FOLLOWING \line COMMANDS WITH \framebox *)
(* THIS WOULD BE SHORTER, BUT WILL NOT WORK PROPERLY!!!!! *)
(*¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡*)
(*=====================================================================*)
IF CPCGlobal.text[x,y-1]="\o" THEN
err:=err OR Put(out,SYSTEM.ADR(" \\linethickness{0.35mm}\n"),0);
ELSE
err:=err OR Put(out,SYSTEM.ADR(" \\linethickness{0.15mm}\n"),0);
END;
err:=err OR Put(out,SYSTEM.ADR(" \\put("),0);
Int2Str(x-1,nums);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
Int2Str(CPCGlobal.ymax-(y-1)+1,nums);
err:=err OR Put(out,SYSTEM.ADR(",\o"),0);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
err:=err OR Put(out,SYSTEM.ADR("){\\line(1,0){1}}\n"),0);
IF CPCGlobal.text[x-1,y]="\o" THEN
err:=err OR Put(out,SYSTEM.ADR(" \\linethickness{0.35mm}\n"),0);
ELSE
err:=err OR Put(out,SYSTEM.ADR(" \\linethickness{0.15mm}\n"),0);
END;
err:=err OR Put(out,SYSTEM.ADR(" \\put("),0);
Int2Str(x-1,nums);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
Int2Str(CPCGlobal.ymax-(y-1)+1,nums);
err:=err OR Put(out,SYSTEM.ADR(",\o"),0);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
err:=err OR Put(out,SYSTEM.ADR("){\\line(0,-1){1}}\n"),0);
IF CPCGlobal.text[x,y+1]="\o" THEN
err:=err OR Put(out,SYSTEM.ADR(" \\linethickness{0.35mm}\n"),0);
err:=err OR Put(out,SYSTEM.ADR(" \\put("),0);
Int2Str(x-1,nums);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
Int2Str(CPCGlobal.ymax-y+1,nums);
err:=err OR Put(out,SYSTEM.ADR(",\o"),0);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
err:=err OR Put(out,SYSTEM.ADR("){\\line(1,0){1}}\n"),0);
END;
IF CPCGlobal.text[x+1,y]="\o" THEN
err:=err OR Put(out,SYSTEM.ADR(" \\linethickness{0.35mm}\n"),0);
err:=err OR Put(out,SYSTEM.ADR(" \\put("),0);
Int2Str(x,nums);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
Int2Str(CPCGlobal.ymax-(y-1)+1,nums);
err:=err OR Put(out,SYSTEM.ADR(",\o"),0);
err:=err OR Put(out,SYSTEM.ADR(nums),0);
err:=err OR Put(out,SYSTEM.ADR("){\\line(0,-1){1}}\n"),0);
END;
END;
END;
END;
err:=err OR Put(out,SYSTEM.ADR(" \\end{picture}\n"),0);
err:=err OR PutWordList(out,TRUE);
err:=err OR Put(out,SYSTEM.ADR("\\end{document}\n"),0);
DosL.Close(out);
out:=NIL;
END;
END;
IF err THEN
again:=HandleIOErr(printC,body);
ELSE
again:=FALSE;
END;
UNTIL NOT again;
IF out#NIL THEN
DosL.Close(out);
out:=NIL;
END;
END PrintTexCross;
BEGIN
printer:=NIL;
parallel:=NIL;
scr:=SYSTEM.CAST(IntuiIO.SCREEN,NIL);
filepresent:=FALSE;
CLOSE
IF scr#NIL THEN
IntuiIO.CloseScreen(scr);
scr:=SYSTEM.CAST(IntuiIO.SCREEN,NIL);
END;
IF printer#NIL THEN
DosL.Close(printer);
printer:=NIL;
END;
IF parallel#NIL THEN
DosL.Close(parallel);
parallel:=NIL;
END;
IF (CPCGlobal.words[0]#NIL) AND (CPCGlobal.words[1]#NIL) THEN
ExecL.FreeMem(CPCGlobal.words[1],SYSTEM.CAST(LONGINT,CPCGlobal.words[0]));
CPCGlobal.words[0]:=NIL;
CPCGlobal.words[1]:=NIL;
END;
END CPCDosIO.